﻿using System.Xml.Serialization;
using System;

namespace DC2010.Objects
{
    public class CurrentNormal : ICloneable
    {
		public CurrentNormal()
		{}
		
		public CurrentNormal(int cur, int max)
		{
			Current = cur;
			Max = max;
		}
        /// <summary>
        /// Current stat
        /// </summary>
        [XmlAttribute]
        public int Current { get; set; }

        /// <summary>
        /// Stat max value
        /// </summary>
        [XmlAttribute]
        public int Max { get; set; }

        /// <summary>
        /// Stat max value
        /// </summary>
        [XmlAttribute]
        public int Min { get; set; }

        /// <summary>
        /// Boosted value
        /// </summary>
        [XmlAttribute]
        public int BoostedAmount { get; set; }

        [XmlIgnore]
        public bool Boosted
        {
            get
            {
                return BoostedAmount > 0;
            }
        }

        /// <summary>
        /// Lowers value. If it is lower than 0, than 0 is set.
        /// </summary>
        /// <param name="amount">Amount to change</param>
        public void Dec(int amount)
        {
            Current = Current - amount;
            if (Current < 0) Current = 0;
        }

        /// <summary>
        /// Increase the value. If it is higher than max, than max is set.
        /// </summary>
        /// <param name="amount">Amount to change</param>
        public void Add(int amount)
        {
            Current = Current + amount;
            if (Current > Max) Current = Max;
        }

        public float Percent
        {
            get
            {
                return Current / ((float)Max / 100);       
            }
        }

        public void IncrMaximum(int majorAttributeMaxIncrement)
        {
            Max += majorAttributeMaxIncrement;
        }

        public void Init(int current, int max)
        {
            Current = current;
            Max = max;
        }

        public void SetCurrent(int p)
        {
            Current = p;
        }

        public void Incr(int Amount)
        {
            Current += Amount;
        }

        public void SetMax(int max)
        {
            Max = max;
        }

        public override string ToString()
        {
            return string.Format("{0} / {1}", Current, Max);
        }

        public object Clone()
        {
            return MemberwiseClone();
        }
    }
}
